package cn.efunbox.afw.core.test.snowflakeld;

import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.CountDownLatch;

public class Work implements Runnable{
        private CountDownLatch downLatch;
        private String name;
        private int k;
        public  Set<Long> set;
        public Work(CountDownLatch downLatch, String name, int k){
            this.downLatch = downLatch;
            this.name = name;
            this.k=k;
        }
        public void run() {
            this.doWork();
            // TODO Auto-generated method stub
            Set<Long> a=new HashSet<>();
            int j=0;
            Long start=System.currentTimeMillis();
            SnowflakeIdWorker SnowflakeIdUtil=   SnowflakeIdWorker.getSnowflakeIdWorker(k,0);
            System.out.println(SnowflakeIdUtil);
            while (j<500000){
                Long x= SnowflakeIdUtil.nextId();
                a.add(x);
                j++;
            }
            set=new HashSet();
            set.addAll(a);
            System.out.println( (System.currentTimeMillis()-start) +"size ="+a.size()+"ss="+set.size());
            this.downLatch.countDown();
        }
        private void doWork(){
            System.out.println(this.name + "正在干活!");
        }
    }